﻿@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model ShenNius.Sys.API.Domain.Entity.Tenant
@section css{
<style>
    .layui-form-item .layui-input {
        width: 350px;
        padding-right: 10px;
        line-height: 38px;
    }
    .layui-form-item .layui-textarea {
        width: 350px;
    }
    .layui-form-select {
        width: 350px;
    }
    .layui-upload-img {
        width: 135px;
        height: 95px;
        padding-left: 110px;
    }
</style>
}
@*id="siteForm"*@
<form  class="layui-form" action="" lay-filter="config-edit">
    <div class="layuimini-container layuimini-page-anim">
        <div class="layuimini-main">
            <div class="layui-form layuimini-form">
                <div class="baseInfo">
                    @if (Model.Id > 0)
                    {
                        <div class="layui-form-item">
                            <label class="layui-form-label">编号</label>
                            <div class="layui-input-block">
                                <input type="text" name="id" lay-verify="id" value="@Model.Id" disabled class="layui-input">
                            </div>
                        </div>
                    }
                    <div class="layui-form-item">
                          <label class="layui-form-label required">租户名称</label>
                        <div class="layui-input-block">
                            <input type="text" placeholder="请填写租户名称" lay-verify="required" name="name" class="layui-input" value="@Model.Name" lay-reqtext="租户名称不能为空" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label required" >站点域名</label>
                        <div class="layui-input-block">
                            <input type="text" name="url" placeholder="请填写入站点域名" value="@Model.Url" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label required">版权</label>
                        <div class="layui-input-block">
                            <input type="text" name="copyright" placeholder="请填写版权" value="@Model.Copyright" class="layui-input" lay-verify="copyright">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label required">联系邮箱</label>
                        <div class="layui-input-block">
                            <input type="text" name="email" placeholder="请填写入联系邮箱" lay-verify="required" value="@Model.Email" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label required">标题</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" placeholder="请填写入站点标题" value="@Model.Title" class="layui-input"  lay-verify="required">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label required">关键字:</label>
                        <div class="layui-input-block">
                            <input type="text" name="keyword" placeholder="请填写入站点关键字" value="@Model.Keyword" class="layui-input"  lay-verify="required">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label required">描述:</label>
                        <div class="layui-input-block">
                            <textarea name="description" placeholder="请输入备注" class="layui-textarea" lay-verify="required">@Model.Description</textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label ">是否关闭</label>
                        <div class="layui-input-block">
                            @if (Model.Status)
                            {
                                <input type="checkbox" checked name="status" value="true" lay-skin="switch">
                            }
                            else
                            {
                                <input type="checkbox" name="status" value="false" lay-skin="switch">
                            }
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">关闭原因</label>
                        <div class="layui-input-block">
                            <textarea name="closeInfo" placeholder="请输入关闭原因" value="@Model.CloseInfo" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>

                <div class="otherInfo" style="display:none;">
                    <div class="layui-form-item">
                        <label class="layui-form-label required">公司电话</label>
                        <div class="layui-input-block">
                            <input type="text" name="tel" placeholder="请填写入公司电话" value="@Model.Tel" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label required">公司传真</label>
                        <div class="layui-input-block">
                            <input type="text" name="fax" placeholder="请填写入公司传真" value="@Model.Fax" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label required">联系地址</label>
                        <div class="layui-input-block">
                            <input type="text" name="address" placeholder="请填写入公司联系地址" value="@Model.Address" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">客服QQ</label>
                        <div class="layui-input-block">
                            <input type="text" name="qQ" placeholder="请填写入公司客服QQ" value="@Model.QQ" class="layui-input" lay-verify="qQ">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">备注</label>
                        <div class="layui-input-block">
                            <textarea name="summary" placeholder="请输入备注"  class="layui-textarea">@Model.Summary</textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label required">微信</label>
                        <div class="layui-upload">
                            <button type="button" class="layui-btn" id="test1">上传图片</button>
                            <div class="layui-upload-list">
                                @if (!string.IsNullOrEmpty(Model.WeiXin))
                                {
                                    <img class="layui-upload-img" id="demo1" src="@Model.WeiXin">
                                    <input type="hidden" id="weiXin" name="weiXin" class="layui-input" value="@Model.WeiXin" lay-verify="required">
                                }
                                else
                                {
                                    <img class="layui-upload-img" id="demo1">
                                    <input type="hidden" id="weiXin" name="weiXin" class="layui-input" lay-verify="required">
                                }
                            </div>

                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">微博</label>
                        <div class="layui-upload">
                            <button type="button" class="layui-btn" id="test2">上传图片</button>
                            <div class="layui-upload-list">
                                @if (!string.IsNullOrEmpty(Model.WeiBo))
                                {
                                    <img class="layui-upload-img" id="weiBoSrc" src="@Model.WeiBo">
                                    <input type="hidden" id="weiBo" name="weiBo" class="layui-input" value="@Model.WeiBo">
                                }
                                else
                                {
                                    <img class="layui-upload-img" id="weiBoSrc">
                                    <input type="hidden" id="weiBo" name="weiBo" class="layui-input">
                                }
                            </div>

                        </div>
                    </div>                 
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block" style="display:inline-flex;">
                        <button type="button" class="layui-btn layui-btn-normal" id="next" lay-submit lay-filter="formStep">下一步</button>
                        <button type="button" class="layui-btn layui-btn-normal" id="up" lay-submit lay-filter="formStep2" style="display:none">
                            上一步
                        </button>
                        <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>


@section js{
<script>
        layui.use(['form', 'common', 'upload'], function () {
            var $ = layui.$,
                form = layui.form,
                upload = layui.upload,
                apiUtil = layui.common;
            $(function () {
                $("#next").click(function () {
                    $(".baseInfo").css("display", "none");
                    $(".otherInfo").css("display", "block");//
                    $("#up").css("display", "block");
                    $("#next").css("display", "none");
                });
                $("#up").click(function () {
                    $(".baseInfo").css("display", "block");
                    $(".otherInfo").css("display", "none");
                    $("#up").css("display", "none");
                    $("#next").css("display", "block");
                });
            });

            //普通图片上传
        var obj=function(idDom,imgDom,inputDom,fileDirectory){
               var model= {
                    elem: "#"+idDom
                    , accept: 'file' //普通文件
                    , url: apiUtil.apiUrl() + 'sys/upload/file'
                    , before: function (obj) {
                        //预读本地文件示例，不支持ie8
                        obj.preview(function (index, file, result) {
                            $("#"+imgDom).attr('src', result);
                        });
                    }
                     ,method:"post"
                     ,data:{
                         directory:function () {return fileDirectory;},
                     }
                    , done: function (res) {
                        if (res.statusCode==200&&res.success == true) {
                            $("#"+imgDom).attr('src', res.data);
                            $("#"+inputDom).val(res.data);
                        }else{
                        layer.msg(res.msg);
                        return false;
                        }
                        //上传成功
                    }, error: function () {
                           layer.msg("上传失败了，请稍后重试！");
                        }
                }
                return model;
            };

            upload.render(
            obj("test1","demo1","weiXin","sys")
            );
             upload.render(
            obj("test2","weiBoSrc","weiBo","sys")
            );

            var parentIndex = parent.layer.getFrameIndex(window.name);
            form.on('submit(saveBtn)', function (data) {
                if (data.field.id > 0) {
                    apiUtil.ajax('sys/tenant/modify', data.field, "application/json", "put", function (res) {
                        if (res.statusCode == 200 && res.success == true) {
                            apiUtil.success(res.msg);
                            parent.layer.close(parentIndex);
                        } else {
                            apiUtil.error(res.msg);
                        }
                    });
                } else {
                    apiUtil.ajax('sys/tenant/add', data.field, "application/json", "post", function (res) {
                        if (res.statusCode == 200 && res.success == true) {
                            apiUtil.success(res.msg);
                            parent.layer.close(parentIndex);
                        } else {
                            apiUtil.error(res.msg);
                        }
                    });
                }
                return false;
            });
        })
</script>
}

